<template>
    <span class="el-button el-button--primary file-input-button">
        <span>上传</span>
        <input accept="image/*" type="file" capture="camera" @change="uploadFile($event)">
    </span>
</template>

<script>
    import util from 'assets/js/util.js'

    export default {
        components: {
            ElButton,
        },
        data () {
            return {
                _file: null
            }
        },
        mounted () {

        },
        methods: {
            uploadFile: function (event) {
                this._file = event.target.files[0];

                const _self = this;
                let form = new FormData();
                form.append('file', this._file);
                util.ajaxByForm({
                    url:  `/file/upload/` + util.getUrlParam(document.location.href, 'caseId'),
                    form: form,
                    success: function (data) {
                        _self.$emit('getFileList', data.message)
                    }
                });
            }
        }
    }
</script>

<style>
    .file-input-button {
        text-align: left;
        position: relative;
        display: inline-block;
        overflow: hidden;
    }

    .file-input-button input {
        position: absolute;
        right: 0;
        top: 0;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
        font-size: 200px;
    }
</style>
